home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / gui / select_gc.lha / select_gc / SGCustomTest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-05-28  |  7.1 KB  |  228 lines

  1.  
  2.  
  3. /*  Select.gadget test 2 (25.5.98)  */
  4. /*  Written for SAS/C               */
  5. /*  Compile: SC LINK SGCustomTest   */
  6. /*  © 1998 Massimo Tantignone       */
  7.  
  8.  
  9. #include "exec/types.h"
  10. #include "dos/dos.h"
  11. #include "intuition/intuition.h"
  12. #include "intuition/gadgetclass.h"
  13. #include "libraries/gadtools.h"
  14. #include "proto/intuition.h"
  15. #include "proto/gadtools.h"
  16. #include "proto/exec.h"
  17.  
  18. #include <gadgets/select.h>
  19. #include <clib/selectgadget_protos.h>
  20. #include <pragmas/selectgadget_pragmas.h>
  21.  
  22.  
  23. /* The library base for the "select.gadget" class library */
  24.  
  25. struct Library *SelectGadgetBase;
  26.  
  27.  
  28. ULONG main(void)
  29. {
  30.    /* The usual stuff */
  31.  
  32.    struct Screen *scr;
  33.    struct Window *win;
  34.    struct IntuiMessage *imsg;
  35.    struct DrawInfo *dri;
  36.    APTR vi;
  37.    ULONG class, code, fine = FALSE;
  38.    ULONG width = 640, height = 200;
  39.    ULONG one = FALSE, two = FALSE;
  40.    struct NewGadget ng;
  41.    struct Gadget *gad1, *gad2, *glist = NULL;
  42.    struct Gadget *iaddress;
  43.    STRPTR labels1[] = { "First option",
  44.                         "Second option",
  45.                         "Third option",
  46.                         "Fourth option",
  47.                         NULL };
  48.    STRPTR labels2[] = { "This is a",
  49.                         "GadTools gadget",
  50.                         "which was made",
  51.                         "pop-up",
  52.                         "by the support",
  53.                         "functions of",
  54.                         "the select.gadget",
  55.                         "library.",
  56.                         NULL };
  57.  
  58.    /* Let's try to open the "select.gadget" library any way we can */
  59.  
  60.    SelectGadgetBase = OpenLibrary("select.gadget",40L);
  61.  
  62.    if (!SelectGadgetBase)
  63.       SelectGadgetBase = OpenLibrary("Gadgets/select.gadget",40L);
  64.  
  65.    if (!SelectGadgetBase)
  66.       SelectGadgetBase = OpenLibrary("Classes/Gadgets/select.gadget",40L);
  67.  
  68.    /* Really not found? Then quit (and complain a bit) */
  69.  
  70.    if (!SelectGadgetBase) return (RETURN_FAIL);
  71.  
  72.    /* Inquire about the real screen size */
  73.  
  74.    if (scr = LockPubScreen(NULL))
  75.    {
  76.       width = scr->Width;
  77.       height = scr->Height;
  78.       UnlockPubScreen(NULL,scr);
  79.    }
  80.  
  81.    /* Open a window on the default public screen */
  82.  
  83.    if (win = OpenWindowTags(NULL,WA_Left,(width - 500) / 2,
  84.                                  WA_Top,(height - 160) / 2,
  85.                                  WA_Width,500,WA_Height,160,
  86.                                  WA_MinWidth,100,WA_MinHeight,100,
  87.                                  WA_MaxWidth,-1,WA_MaxHeight,-1,
  88.                                  WA_CloseGadget,TRUE,
  89.                                  WA_SizeGadget,TRUE,
  90.                                  WA_DepthGadget,TRUE,
  91.                                  WA_DragBar,TRUE,
  92.                                  WA_SimpleRefresh,TRUE,
  93.                                  WA_Activate,TRUE,
  94.                                  WA_Title,"select.gadget custom gadget test",
  95.                                  WA_IDCMP,IDCMP_CLOSEWINDOW |
  96.                                           IDCMP_GADGETUP |
  97.                                           IDCMP_REFRESHWINDOW,
  98.                                  TAG_END))
  99.    {
  100.       /* Get the screen's DrawInfo, it will be useful... */
  101.  
  102.       if (dri = GetScreenDrawInfo(win->WScreen))
  103.       {
  104.          /* Same for the VisualInfo */
  105.  
  106.          if (vi = GetVisualInfoA(win->WScreen,NULL))
  107.          {
  108.             /* Create two gadgets, the GadTools way */
  109.  
  110.             glist = CreateContext(&glist);
  111.  
  112.             /* The width isn't very accurate, but this is just an example */
  113.  
  114.             ng.ng_LeftEdge = 40;
  115.             ng.ng_TopEdge = win->BorderTop + 40;
  116.             ng.ng_Width = win->WScreen->RastPort.Font->tf_XSize * 18 + 30;
  117.             ng.ng_Height = win->WScreen->Font->ta_YSize + 6;
  118.             ng.ng_GadgetText = "G_adTools 1";
  119.             ng.ng_TextAttr = win->WScreen->Font;
  120.             ng.ng_GadgetID = 1;
  121.             ng.ng_Flags = 0L;
  122.             ng.ng_VisualInfo = vi;
  123.  
  124.             gad1 = CreateGadget(GENERIC_KIND,glist,&ng,GT_Underscore,'_',TAG_END);
  125.  
  126.             ng.ng_LeftEdge = win->Width - 40 - ng.ng_Width;
  127.             ng.ng_TopEdge += 40;
  128.             ng.ng_GadgetText = "Ga_dTools 2";
  129.             ng.ng_GadgetID = 2;
  130.  
  131.             gad2 = CreateGadget(GENERIC_KIND,gad1,&ng,GT_Underscore,'_',TAG_END);
  132.  
  133.             /* If all went ok, transform the gadgets and use them */
  134.  
  135.             if (gad2)
  136.             {
  137.                one = InitSelectGadget(gad1,0L,GA_DrawInfo,dri,
  138.                                               SGA_TextPlace,PLACETEXT_RIGHT,
  139.                                               SGA_Labels,labels1,
  140.                                               SGA_DropShadow,TRUE,
  141.                                               SGA_FollowMode,SGFM_KEEP,
  142.                                               TAG_END);
  143.  
  144.                two = InitSelectGadget(gad2,0L,GA_DrawInfo,dri,
  145.                                               SGA_TextPlace,PLACETEXT_LEFT,
  146.                                               SGA_Labels,labels2,
  147.                                               SGA_Active,3,
  148.                                               SGA_ItemSpacing,2,
  149.                                               SGA_PopUpPos,SGPOS_BELOW,
  150.                                               SGA_SymbolWidth,-21,
  151.                                               TAG_END);
  152.  
  153.                /* Add the gadgets to the window and display them */
  154.  
  155.                AddGList(win,glist,-1,-1,NULL);
  156.                RefreshGList(glist,win,NULL,-1);
  157.                GT_RefreshWindow(win,NULL);
  158.             }
  159.  
  160.             /* Now let's handle the events until the window gets closed */
  161.  
  162.             while (!fine)
  163.             {
  164.                Wait(1 << win->UserPort->mp_SigBit);
  165.  
  166.                while (imsg = GT_GetIMsg(win->UserPort))
  167.                {
  168.                   class = imsg->Class;
  169.                   code = imsg->Code;
  170.                   iaddress = imsg->IAddress;
  171.                   GT_ReplyIMsg(imsg);
  172.  
  173.                   if (class == IDCMP_CLOSEWINDOW) fine = TRUE;
  174.  
  175.                   if (class == IDCMP_GADGETUP) printf("Gadget: %ld, Item: %ld\n",
  176.                                                       iaddress->GadgetID,
  177.                                                       code);
  178.  
  179.                   if (class == IDCMP_REFRESHWINDOW)
  180.                   {
  181.                      GT_BeginRefresh(win);
  182.                      GT_EndRefresh(win,TRUE);
  183.                   }
  184.                }
  185.             }
  186.  
  187.             /* If the gadgets were added, remove them */
  188.  
  189.             if (gad2)
  190.             {
  191.                RemoveGList(win,glist,-1);
  192.             }
  193.  
  194.             /* Strip the gadgets of additional "select" information */
  195.  
  196.             if (one) ClearSelectGadget(gad1);
  197.             if (two) ClearSelectGadget(gad2);
  198.  
  199.             /* Dispose the gadgets; FreeGadgets() ignores NULL arguments */
  200.  
  201.             FreeGadgets(glist);
  202.  
  203.             /* Free the VisualInfo */
  204.  
  205.             FreeVisualInfo(vi);
  206.          }
  207.  
  208.          /* Release the DrawInfo structure */
  209.  
  210.          FreeScreenDrawInfo(win->WScreen,dri);
  211.       }
  212.  
  213.       /* Say good-bye to the window... */
  214.  
  215.       CloseWindow(win);
  216.    }
  217.  
  218.    /* ... and to the library */
  219.  
  220.    CloseLibrary(SelectGadgetBase);
  221.  
  222.    /* We did our job, now let's go home :-) */
  223.  
  224.    return (RETURN_OK);
  225. }
  226.  
  227.  
  228.